'''
    本模块提供了许多工具函数

    用于方便其他模块的工作
'''

import time
import json


def get_file_data(file):
    with open(file, 'r', encoding='utf-8') as f:
        data = f.read()
    if data:
        return data
    else:
        return ''

def notFound(http_request_data, response):
    response_data = "HTTP/1.0 200 OK\r\n"
    response_data += "Content-Type: text/html; charset=UTF-8\r\n\r\n"
    response_data += get_file_data('./web_file/notFound.html')
    response_data = response_data.encode('utf-8')
    response.sendall(response_data)

# 用于读取配置
def load_pro_conf():
    print(f'[{int(time.time())}] 正在读取配置信息')
    with open('./config/config.json', 'r', encoding='utf-8') as f:
        conf = json.load(f)
    return conf
